#ifndef SLIDERWIDGET_H
#define SLIDERWIDGET_H

#include <QObject>
#include <QWidget>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QEventLoop>

class SlideWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SlideWidget(QWidget* parent=nullptr);

    /**
     * @brief The ACTION enum       动作
     */
    enum ACTION{
        SLIDER_UP,
        SLIDER_DOWN,
        SLIDER_LEFT,
        SLIDER_RIGHT,
        SLIDER_INVALID
    };

    /**
     * @brief The POSITION enum         widget的位置
     */
    enum POSITION{
        UP,
        DOWN,
        LEFT,
        RIGHT,
        CENTRE
    };

    /**
     * @brief The CURRENTWIDGET enum        当前显示窗口位置
     */
    enum CURRENTWIDGET{
        STATE_UP,
        STATE_DOWN,
        STATE_LEFT,
        STATE_RIGHT,
        STATE_CENTRE
    };

    /**
     * @brief setWdiget         设置窗口
     * @param pos
     * @param widget
     */
    void setWidget(const POSITION& pos, QWidget* widget);

    /**
     * @brief getWidget     获取窗口
     * @param pos
     * @return
     */
    QWidget* getWidget(const POSITION& pos);


    SlideWidget::CURRENTWIDGET getCurrentPos() const;
    void setCurrentPos(const SlideWidget::CURRENTWIDGET &value);

    /**
     * @brief getSensitivity    敏感度操作
     */
    unsigned getSensitivity() const;
    void setSensitivity(const unsigned &value);

    /**
     * @brief getDuration       动画持续时间
     * @return
     */
    int getDuration() const;
    void setDuration(int value);

    float getScale() const;
    void setScale(float value);



    QEasingCurve getEasingCurve() const;
    void setEasingCurve(const QEasingCurve &value);

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void leaveEvent(QEvent *event);
    void resizeEvent(QResizeEvent *event);

signals:

    void sliderAction(SlideWidget::ACTION&);

public slots:
    /**
     * @brief restore 还原
     */
    void restore();

    /**
     * @brief sliderUp      向上滑动
     */
    void sliderUp();

    /**
     * @brief sliderDown    向下滑动
     */
    void sliderDown();

    /**
     * @brief sliderLeft    向左滑动
     */
    void sliderLeft();

    /**
     * @brief sliderRight   向右滑动
     */
    void sliderRight();

private:
    bool mousePressed;      //鼠标点击状态
    QPoint leftPressPos;    //鼠标左键点击位置
    CURRENTWIDGET currentState;  //当前窗口位置
    unsigned sensitivity;      //设置敏感度
    int duration;       //动画执行时间
    float scale;        //比例
    QEasingCurve easingCurve;
    QRect endRect;
    QRect endRect1;

    QWidget* upWidget,*downWidget,*leftWidget,*rightWidget,*centreWidget;

    void loop(QPropertyAnimation& animation);
    /**
     * @brief init          初始化参数
     */
    void init();

    /**
     * @brief sliderDirection       获取滑动方向
     * @param startPos
     * @param endPos
     * @return
     */
    ACTION sliderDirection(const QPoint& startPos, const QPoint& endPos );
};

#endif // SLIDERWIDGET_H
